package com.infindo.appcreate.zzyj.servlet;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Properties;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import com.infindo.appcreate.zzyj.util.Constant;

public class SysListener extends HttpServlet implements ServletContextListener {

	private static final long serialVersionUID = 0xe5a9f33cc18dab6L;
	private static final Logger logger = LoggerFactory
			.getLogger(SysListener.class);

	
	
	public void contextInitialized(ServletContextEvent sce) {
		logger.info("ContextInitialized START...");
		System.setProperty("java.awt.headless", "true");
		System.setProperty("jmagick.systemclassloader", "no");
		String rootpath = sce.getServletContext().getRealPath("/");
		if (rootpath != null)
			rootpath = rootpath.replaceAll("\\\\", "/");
		else
			rootpath = "/";
		if (!rootpath.endsWith("/"))
			rootpath = (new StringBuilder()).append(rootpath).append("/")
					.toString();
		Constant.SYSTEM_ROOT_PATH = rootpath;
		Constant.CONTENT_PATH = sce.getServletContext().getContextPath();
		
		//HttpServletRequest request = ((ServletRequestAttributes)ra).getRequest();   
//		String str=File.separator;
//		String p = str+"WEB-INF"+str+"classes"+str+"appConfig.properties";
//        InputStream path=this.getServletContext().getResourceAsStream(p);
//
//        Properties pros = new Properties();
//        try {
//            pros.load(path);
//        } catch (IOException ex) {
//            System.out.println("file is not exist");
//        }
//        Constant.IOS_APP_BUILD_DIR = pros.getProperty("username");
	}

	public void contextDestroyed(ServletContextEvent servletcontextevent) {
	}

}